package client.comm.baoding.ui

import android.content.Intent
import android.text.TextUtils
import androidx.lifecycle.Observer
import client.comm.commlib.dialog.ValidatePwdDialog
import client.comm.commlib.toast.toast
import client.comm.commlib.utils.StoreUtil
import client.comm.baoding.R
import client.comm.baoding.ui.vm.TxViewModel
import client.comm.baoding.api.bean.UserInfo
import client.comm.baoding.BaseMiddleActivity
import client.comm.baoding.databinding.ActivityKTx1Binding

class BankkTxSimpleActivity : BaseMiddleActivity<TxViewModel, ActivityKTx1Binding>() {

    override fun getLayout(): Int {
        return R.layout.activity_k_tx_1
    }

    override fun initViewModel(): TxViewModel = createViewModel()

    override fun initView() {
        binding?.apply {
            event = this@BankkTxSimpleActivity
            vm = viewModel
            StoreUtil.getBean<UserInfo>(this@BankkTxSimpleActivity)?.let {
                viewModel.userInfo.value = it
                incomeTx = it.income_tx.toString()
            }
        }
    }

    override fun observerUI() {
        viewModel.call_kt.observe(this, Observer {
            it?.apply {
                if (isSuccess) {
                    toast("操作成功")
                    it.data?.let {
                        startActivity(Intent(this@BankkTxSimpleActivity, Bank3CodeActivity::class.java).apply {
                            putExtra("bank_bind", it)
                            putExtra("status", "3")
                        })
                    }
                    finish()
                } else {
                    toast(it.message)
                }
            }
        })

    }


    fun ok() {
       var link_id= intent.getStringExtra("link_id")

        if (TextUtils.isEmpty(viewModel.txNum.value)) {
            toast("所有不能为空")
            return
        }

        ValidatePwdDialog(this).apply {
            title = "需要验证支付密码"
            ok = {
                viewModel.ok_tx(it,link_id!!)
            }

        }.show()
    }

    fun jl() {
        startActivity(Intent(this, KtOrderActivity::class.java))
    }

}